package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"product/models"
	"product/utils"
	"strconv"
)

/**
 *@author:zhengyilong
 *@email:1797344574@qq.com
 *@phone:13479394730
 *@DateTime:2021/12/17 19:10
 **/

type ProductController struct {
	beego.Controller
}

func (pro *ProductController) Get() {
	pro.TplName="index.html"
}

//自定义路由
func (pro *ProductController) QueryMessage() {
	id, err := pro.GetInt("inputId")
	utils.LogInfo("用户输入id:"+strconv.Itoa(id))
	if err != nil {
		//fmt.Println("获取id失败：",err)
		utils.LogError("获取id失败："+err.Error())
		return
	}
	result := models.QueryProductMessage(id)
	utils.LogInfo("查询到一条数据："+strconv.Itoa(id)+string(result.Name)+string(result.Producer)+string(result.Createdate))
	pro.Data["json"] = &result
	pro.ServeJSON()
}